#include "play.hpp"
#include <iostream>
#include "ship.hpp"

Play::Play (void){};

int Play::Run (sf::RenderWindow &App)
{
    bool Running = true;
    sf::Sprite background;
    sf::Texture backGroundTexture;
    sf::Event Event;
    sf::Sprite testSprite;
    sf::Texture testTexture;

    b2Vec2 gravity = b2Vec2(0.0f,0.0f);
    b2World* gameWorld = new b2World(gravity);
    Ship* playerShip = new Ship ("Destroyer", "../images/playerShip.png", gameWorld);

    if (!backGroundTexture.loadFromFile("../images/starfield.png"))
    {
        std::cerr<<"Error loading starfield"<<std::endl;
       return (-1);
    }
    background.setTexture(backGroundTexture);
    App.clear(sf::Color(0, 0, 0, 0));

    while (Running)
    {
        //Verifying events
        while (App.pollEvent(Event))
        {
            // Window closed
            if (Event.type == sf::Event::Closed)
            {
                return (-1);
            }
            //Key pressed
            if (Event.type == sf::Event::KeyPressed)
            {
                switch (Event.key.code)
                {
                    case sf::Keyboard::Escape:
                        return (-1);
                        break;
                    default :
                        break;
                }
            }
        }

        playerShip->update();

        App.draw(background);
        App.draw(playerShip->getSprite());
        App.display();
    }
    return (-1);
} 
